package com.sys.app.entity.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

public class JavaBeanUtil {

    public static Object MapToJavaBean(Map<String, Object> map, Object obj) {
        try {
            Class bean = obj.getClass();
            Field[] fields = bean.getDeclaredFields();
            for (Field field : fields) {
                String key = field.getName();
                Class type = field.getType();
                Method method = bean.getDeclaredMethod("set" + StringUtil.camel2Underscore(key), type);
                Object value = method.invoke(obj, map.get(key));
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return obj;
    }
}
